Money!
[andmenj-acm.git] / 608 - Counterfeit Dollar / 608.cpp
blob30fcaf3c4a2830a82ef8c374d9f0f7f1f53c0d7d
1 using namespace std;
2 #include <algorithm>
3 #include <iostream>
4 #include <iterator>
5 #include <numeric>
6 #include <sstream>
7 #include <fstream>
8 #include <cassert>
9 #include <climits>
10 #include <cstdlib>
11 #include <cstring>
12 #include <string>
13 #include <cstdio>
14 #include <vector>
15 #include <cmath>
16 #include <queue>
17 #include <deque>
18 #include <stack>
19 #include <list>
20 #include <map>
21 #include <set>
23 #define foreach(x, v) for (typeof (v).begin() x=(v).begin(); x !=(v).end(); ++x)
24 #define For(i, a, b) for (int i=(a); i<(b); ++i)
25 #define D(x) cout << #x " is " << x << endl
27 string A[3], B[3], C[3];
29 int value(const string &s) {
30 return s == "up" ? +1 : s == "down" ? -1 : 0;
33 bool works(char letter, int v) {
34 for (int i = 0; i < 3; ++i) {
35 int sa = 0, sb = 0;
36 for (int k = 0; k < A[i].size(); ++k) sa += v * (A[i][k] == letter);
37 for (int k = 0; k < B[i].size(); ++k) sb += v * (B[i][k] == letter);
38 if (sa - sb != value(C[i])) return false;
40 return true;
43 int main(){
44 int cases; cin >> cases;
45 while (cases--) {
46 for (int i = 0; i < 3; ++i) cin >> A[i] >> B[i] >> C[i];
47 for (char c = 'A'; c <= 'Z'; ++c) {
48 if (works(c, +1)) {
49 printf("%c is the counterfeit coin and it is heavy.\n", c);
50 break;
52 if (works(c, -1)) {
53 printf("%c is the counterfeit coin and it is light.\n", c);
54 break;
58 return 0;